var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../utils/util")), a = getApp(), e = require("../../../mybehaviors/location/location"), i = require("../../../utils/themeSkin/skinBehavior");

Page({
    behaviors: [ i, e ],
    data: {
        active: 1,
        zIndex: 100,
        isBgFlag: !1,
        addressOpen: !1,
        pageOpen: !1,
        makeOpen: !1,
        subscribeFlag: !1,
        subscribeText: "全部分类",
        addressValue: 0,
        presentTime: "",
        addressList: [],
        cityText: "全部区域",
        cityValue: "",
        addressCity: "",
        query: {
            page: 1,
            longitude: "",
            latitude: "",
            city: "",
            travel_around_goods_type: 0,
            is_recommand: 0,
            category: 0,
            title: "",
            cityCode: "",
            basic_info: 1
        },
        addIndex: -1,
        subscribeIndex: 0,
        pageScrollTopV: 0,
        optionIndex: 1,
        container: null,
        indexBanner: [],
        activityList: [],
        classifyList: [],
        rankingList: [],
        goodsList: [],
        locationStatus: !1,
        isLoadMore: !0,
        total_page: 0,
        locationMore: !0,
        showKefu: !1,
        customer_open: "",
        cservice: "",
        service_mobile: "",
        service_QRcode: "",
        formatPoints: "",
        computingFlag: "",
        beforeTime: "",
        siteName: "",
        imageUrl: "",
        localCity: "",
        Hei: ""
    },
    onLoad: function(t) {
        var a;
        "" !== (null !== (a = t.city) && void 0 !== a ? a : "") && (this.setData({
            cityValue: Number(t.cityCode),
            "query.cityCode": Number(t.cityCode),
            "query.city": t.city,
            addressCity: t.city,
            localCity: t.city
        }), this.aroundLocation(), this.getGoodsList()), this.getKefu(), this.travelIndexData();
    },
    travelIndexData: function() {
        var t = this, e = "", i = "";
        this.data.localCity ? i = this.data.localCity || "" : e = this.data.query.cityCode || "";
        var o = a.getNetAddresss("plugin.travel-around.frontend.index.index");
        a._getNetWork({
            url: o,
            data: {
                city: i,
                cityCode: e,
                basic_info: 1
            },
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    var i, o, s, n, d = e.data.category, r = e.basic_info, c = [];
                    d.length > 10 && (c = d.splice(9, d.length - 10)), t.setData({
                        rankingList: e.data.goods,
                        indexBanner: e.data.banner,
                        activityList: d,
                        classifyList: c,
                        siteName: null == r || null === (i = r.home) || void 0 === i || null === (o = i.mailInfo) || void 0 === o ? void 0 : o.name,
                        imageUrl: null == r || null === (s = r.home) || void 0 === s || null === (n = s.mailInfo) || void 0 === n ? void 0 : n.logo_url
                    });
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
                wx.setNavigationBarColor({
                    frontColor: "#ffffff",
                    backgroundColor: t.data.themeBaseColor,
                    animation: {
                        duration: 400,
                        timingFunc: "easeIn"
                    }
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    imgH: function(t) {
        var a = wx.getSystemInfoSync().windowWidth * t.detail.height / t.detail.width + "px";
        this.setData({
            Hei: a
        });
    },
    goTop: function(t) {
        wx.pageScrollTo ? wx.pageScrollTo({
            scrollTop: 0
        }) : wx.showModal({
            title: "提示",
            content: "当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。"
        });
    },
    showService: function() {
        this.setData({
            showKefu: !0
        });
    },
    searchOn: function() {
        wx.navigateTo({
            url: "/packageF/tourAround/tourSearch/tourSearch?keyWord=".concat(this.data.query.title, "&city=").concat(this.data.localCity, "&latitude=").concat(this.data.query.latitude, "&longitude=").concat(this.data.query.longitude, "&cityCode=").concat(this.data.query.cityCode)
        });
    },
    rankingOn: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageF/tourAround/tourAroundGoodsDetails/tourAroundGoodsDetails?goodsId=".concat(a, "&latitude=").concat(this.data.query.latitude, "&longitude=").concat(this.data.query.longitude)
        });
    },
    subscribeOn: function(t) {
        var a = this, e = t.currentTarget.dataset.index, i = !1;
        if (3 === e) this.setData({
            makeOpen: !0,
            pageOpen: !this.data.pageOpen
        }), this.data.isBgFlag ? i = !0 : (i = !1, i = !(!this.data.addressOpen && !this.data.makeOpen)), 
        this.setData({
            subscribeFlag: i
        }), this.data.isBgFlag || this.setData({
            isBgFlag: !this.data.isBgFlag
        }), this.createSelectorQuery().select("#subscribes").boundingClientRect(function(t) {
            t.top > 0 && (wx.pageScrollTo({
                scrollTop: t.top + a.data.pageScrollTopV,
                duration: 0
            }), a.setData({
                isBgFlag: !0
            }));
        }).exec(); else if (1 === e) i = !!this.data.isBgFlag, this.setData({
            makeOpen: !1,
            addressOpen: !1,
            pageOpen: !1,
            subscribeFlag: i,
            "query.is_recommand": 1,
            "query.page": 1
        }), this.getGoodsList(), this.data.subscribeFlag && this.goTop(); else {
            i = !!this.data.isBgFlag, this.setData({
                makeOpen: !1,
                addressOpen: !1,
                subscribeFlag: i,
                pageOpen: !1,
                "query.page": 1
            });
            try {
                this._getLocation(function(t, e) {
                    var i = t.ad_info.adcode.toString().slice(0, 4) + "00";
                    a.setData({
                        "query.latitude": e.lat,
                        "query.longitude": e.lng,
                        cityValue: i
                    }), a.getGoodsList();
                });
            } catch (t) {
                console.log(t), this.getGoodsList();
            }
            this.data.subscribeFlag && this.goTop();
        }
        this.setData({
            subscribeIndex: e
        });
    },
    onPageScroll: t.default.throttle(function(t) {
        var a = t[0];
        this.setData({
            pageScrollTopV: a.scrollTop
        }), a.scrollTop >= 1 ? this.setData({
            isBgFlag: !0
        }) : this.setData({
            isBgFlag: !1
        });
    }, 50),
    maskOn: function() {
        this.setData({
            makeOpen: !1,
            addressOpen: !1,
            pageOpen: !1
        });
    },
    getKefu: function() {
        var t = this, e = a.getNetAddresss("goods.customer-service.index");
        a._postNetWork({
            url: e,
            data: {
                goods_id: ""
            },
            success: function(a) {
                var e = a.data;
                1 == e.result && t.setData({
                    customer_open: 0 != e.data.customer_open,
                    showKefu: !1,
                    cservice: e.data.cservice,
                    service_QRcode: e.data.service_QRcode,
                    service_mobile: e.data.service_mobile
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    swiperNav: function(t) {
        wx.navigateTo({
            url: t
        });
    },
    cityNavOn: function() {
        wx.navigateTo({
            url: "/packageF/tourAround/tourCityList/tourCityList?cityCode=".concat(this.data.cityValue, "&localCity=").concat(this.data.addressCity)
        });
    },
    commodityNav: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageF/tourAround/tourAroundGoodsDetails/tourAroundGoodsDetails?goodsId=" + a
        });
    },
    rankingNav: function() {
        wx.navigateTo({
            url: "/packageF/tourAround/rankingList/rankingList?cityCode=".concat(this.data.cityValue, "&city=").concat(this.data.localCity)
        });
    },
    subscribeOption: function(t) {
        var a = t.currentTarget.dataset, e = a.index, i = a.name;
        this.setData({
            optionIndex: e,
            subscribeText: i,
            makeOpen: !1,
            addressOpen: !1,
            pageOpen: !1,
            "query.travel_around_goods_type": e,
            "query.page": 1
        }), this.data.subscribeFlag && this.goTop(), this.getGoodsList();
    },
    aroundLocation: function() {
        var t = this, e = a.getNetAddresss("plugin.travel-around.frontend.index.index.getTravelAroundLocation"), i = {
            cityCode: this.data.cityValue,
            city: this.data.city
        };
        a._getNetWork({
            url: e,
            data: i,
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    addressList: e.data.matching || []
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    toAddress: function(t) {
        var a = t.currentTarget.dataset, e = a.index, i = a.city;
        this.setData({
            addIndex: e,
            cityText: i,
            "query.city": i,
            addressOpen: !1,
            pageOpen: !1
        }), this.data.subscribeFlag && this.goTop(), this.getGoodsList();
    },
    allArea: function() {
        this.setData({
            addIndex: -1,
            cityText: "全部区域",
            addressOpen: !1
        });
    },
    getGoodsList: function() {
        var t = this;
        "" === this.data.query.latitude && "" === this.data.query.longitude ? this.setData({
            locationMore: !1
        }) : this.setData({
            locationMore: !0
        });
        var e = a.getNetAddresss("plugin.travel-around.frontend.goods.goods.getGoodsList");
        a._postNetWork({
            url: e,
            data: this.data.query,
            success: function(a) {
                var e = a.data;
                wx.hideLoading(), wx.hideNavigationBarLoading(), wx.stopPullDownRefresh(), 1 == e.result ? (t.data.totalPage = e.data.last_page, 
                t.data.totalPage || (t.data.totalPage = 0), t.setData({
                    goodsList: e.data.data
                })) : (t.data.page = t.data.page - 1, t.isLoadMore = !1, wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    addMenuOpen: function() {
        var t = this;
        this.setData({
            addressOpen: !0,
            pageOpen: !this.data.pageOpen,
            makeOpen: !1,
            subscribeIndex: 4
        });
        var a = !1;
        a = !!this.data.isBgFlag, this.data.addressOpen && (a = !0), this.setData({
            subscribeFlag: a
        }), this.data.isBgFlag || this.setData({
            isBgFlag: !this.data.isBgFlag
        }), this.createSelectorQuery().select("#selectAddress").boundingClientRect(function(a) {
            a.top > 0 && wx.pageScrollTo({
                scrollTop: a.top + t.data.pageScrollTopV,
                duration: 0
            });
        }).exec();
    },
    classifyOn: function(t) {
        var a = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageF/tourAround/categories/categories?childrenId=" + a + "&cityCode=".concat(this.data.cityValue, "&city=").concat(this.data.query.city, "&latitude=").concat(this.data.query.latitude, "&longitude=").concat(this.data.query.longitude)
        });
    },
    subscribeSticky: t.default.throttle(function(t) {
        var a = t[0].detail.isFixed;
        void 0 !== a && (a ? this.setData({
            subscribeFlag: !0
        }) : (this.setData({
            subscribeFlag: !1
        }), (this.data.addressOpen || this.data.makeOpen) && this.setData({
            subscribeFlag: !0
        })));
    }),
    getGood: function() {
        var t = this, e = a.getNetAddresss("goods.customer-service.index");
        a._getNetWork({
            url: e,
            data: {
                goods_id: ""
            },
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    serviceQRcode: e.data.service_QRcode,
                    serviceMobile: e.data.service_mobile,
                    cservice: e.data.cservice
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    change: function(t) {
        return t < 10 ? "0" + t : t;
    },
    getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.query.page >= this.data.totalPage)) {
            this.data.query.page = this.data.query.page + 1;
            var e = a.getNetAddresss("plugin.travel-around.frontend.goods.goods.getGoodsList");
            a._getNetWork({
                url: e,
                data: this.data.query,
                success: function(a) {
                    var e = a.data, i = e.data.data;
                    1 == e.result ? (t.data.isLoadMore = !0, t.setData({
                        goodsList: t.data.goodsList.concat(i)
                    })) : (t.data.query.page = t.data.query.page - 1, t.isLoadMore = !1, wx.showToast({
                        icon: "none",
                        title: e.msg,
                        duration: 1500
                    }));
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    onReady: function() {
        var t = this;
        this.setData({
            container: function() {
                return wx.createSelectorQuery().select("#travelIndex");
            },
            presentTime: new Date().getTime()
        });
        try {
            this._getLocation(function(a, e) {
                var i = a.ad_info.adcode.toString().slice(0, 4) + "00";
                t.setData({
                    "query.latitude": e.lat,
                    "query.longitude": e.lng,
                    "query.cityCode": i,
                    cityValue: i
                }), "" === t.data.addressCity && t.setData({
                    addressCity: a.ad_info.city
                }), t.travelIndexData(), t.aroundLocation(), t.getGoodsList();
            });
        } catch (t) {
            this.travelIndexData(), this.aroundLocation(), this.getGoodsList(), console.log(t);
        }
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {
        return {
            title: "周边游-" + this.data.siteName,
            imageUrl: this.data.imageUrl,
            path: "/packageF/tourAround/travelIndex/travelIndex?city=".concat(this.data.query.city, "&cityCode=").concat(this.data.query.cityCode, "&localCity=").concat(this.data.localCity, "&longitude=").concat(this.data.query.longitude, "&latitude=").concat(this.data.query.latitude)
        };
    },
    onShareTimeline: function() {
        return {
            title: "周边游-" + this.data.siteName,
            imageUrl: this.data.imageUrl,
            path: "/packageF/tourAround/travelIndex/travelIndex?city=".concat(this.data.query.city, "&cityCode=").concat(this.data.query.cityCode, "&localCity=").concat(this.data.localCity, "&longitude=").concat(this.data.query.longitude, "&latitude=").concat(this.data.query.latitude)
        };
    }
});